home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr49 / vesa18.zip / VESA.C < prev    next >
C/C++ Source or Header  |  1995-01-24  |  10KB  |  292 lines

  1. #define INCL_DOSMODULEMGR
  2. #define INCL_DOSMISC
  3.  
  4. #include <os2.h>
  5. #include <stdlib.h>
  6. #include <sys/hw.h>
  7.  
  8. #include "vesa.h"
  9. #include "vesa_dos.h"
  10. #include "vgaports.h"
  11.  
  12. static HMODULE hmod;
  13.  
  14. static VESABOOL dummy1(void)
  15. {
  16.   return(TRUE);
  17. }
  18.  
  19. static VESABOOL dummy2(void)
  20. {
  21.   return(FALSE);
  22. }
  23.  
  24. static void MyExit(void)
  25. {
  26.   DosFreeModule(hmod);
  27. }
  28.  
  29. VESABOOL VesaInitialize(void)
  30. {
  31.   if (_osmode == OS2_MODE)
  32.     {
  33.       CHAR Error[100];
  34.       PCSZ EnvVar;
  35.  
  36.       if (DosScanEnv("VESADLL", &EnvVar))
  37.         EnvVar = "VESA_PM";
  38.       if (DosLoadModule(Error, sizeof(Error), EnvVar, &hmod))
  39.         return(FALSE);
  40.       atexit(MyExit);
  41.       if ((DosQueryProcAddr(hmod,  1, NULL, (PFN*) &VesaGetInfo)) ||
  42.           (DosQueryProcAddr(hmod,  2, NULL, (PFN*) &VesaGetModeInfo)) ||
  43.           (DosQueryProcAddr(hmod,  3, NULL, (PFN*) &VesaSetMode)) ||
  44.           (DosQueryProcAddr(hmod,  4, NULL, (PFN*) &VesaGetMode)) ||
  45.           (DosQueryProcAddr(hmod,  5, NULL, (PFN*) &VesaSetWindow)) ||
  46.           (DosQueryProcAddr(hmod,  6, NULL, (PFN*) &VesaGetWindow)) ||
  47.           (DosQueryProcAddr(hmod,  7, NULL, (PFN*) &VesaSetScanlineLength)) ||
  48.           (DosQueryProcAddr(hmod,  8, NULL, (PFN*) &VesaGetScanlineLength)) ||
  49.           (DosQueryProcAddr(hmod,  9, NULL, (PFN*) &VesaSetSwitchFunc)) ||
  50.           (DosQueryProcAddr(hmod, 10, NULL, (PFN*) &VesaLockScreen)) ||
  51.           (DosQueryProcAddr(hmod, 11, NULL, (PFN*) &VesaUnlockScreen)) ||
  52.           (DosQueryProcAddr(hmod, 12, NULL, (PFN*) &VesaSetModified)) ||
  53.           (DosQueryProcAddr(hmod, 13, NULL, (PFN*) &VesaSetPalette)) ||
  54.           (DosQueryProcAddr(hmod, 14, NULL, (PFN*) &VesaGetPalette)) ||
  55.           (DosQueryProcAddr(hmod, 15, NULL, (PFN*) &VesaGetCharacter)) ||
  56.           (DosQueryProcAddr(hmod, 16, NULL, (PFN*) &VesaKeyboardHit)) ||
  57.           (DosQueryProcAddr(hmod, 20, NULL, (PFN*) &MouseOpen)) ||
  58.           (DosQueryProcAddr(hmod, 21, NULL, (PFN*) &MouseClose)) ||
  59.           (DosQueryProcAddr(hmod, 22, NULL, (PFN*) &MouseShow)) ||
  60.           (DosQueryProcAddr(hmod, 23, NULL, (PFN*) &MouseHide)) ||
  61.           (DosQueryProcAddr(hmod, 24, NULL, (PFN*) &MouseSetPosition)) ||
  62.           (DosQueryProcAddr(hmod, 25, NULL, (PFN*) &MouseGetPosition)) ||
  63.           (DosQueryProcAddr(hmod, 26, NULL, (PFN*) &MouseGetEvent)))
  64.         return(FALSE);
  65.       else
  66.         return(TRUE);
  67.     }
  68.   else
  69.     {
  70.       VESAINFO VesaInfo;
  71.  
  72.       _portaccess(PEL_IR, PEL_D);
  73.       _portaccess(IS1_R, IS1_R);
  74.       if (DosVesaGetInfo(&VesaInfo))
  75.         {
  76.           VesaGetInfo           = DosVesaGetInfo;
  77.           VesaGetModeInfo       = DosVesaGetModeInfo;
  78.           VesaSetMode           = DosVesaSetMode;
  79.           VesaGetMode           = DosVesaGetMode;
  80.           VesaSetWindow         = DosVesaSetWindow;
  81.           VesaGetWindow         = DosVesaGetWindow;
  82.           VesaSetScanlineLength = DosVesaSetScanlineLength;
  83.           VesaGetScanlineLength = DosVesaGetScanlineLength;
  84.         }
  85.       else
  86.         {
  87.           VesaGetInfo           = DosNoVesaGetInfo;
  88.           VesaGetModeInfo       = DosNoVesaGetModeInfo;
  89.           VesaSetMode           = DosNoVesaSetMode;
  90.           VesaGetMode           = DosNoVesaGetMode;
  91.           VesaSetWindow         = DosNoVesaSetWindow;
  92.           VesaGetWindow         = DosNoVesaGetWindow;
  93.           VesaSetScanlineLength = DosNoVesaSetScanlineLength;
  94.           VesaGetScanlineLength = DosNoVesaGetScanlineLength;
  95.         }
  96.       VesaSetSwitchFunc     = (void *) dummy1;
  97.       VesaLockScreen        = (void *) dummy1;
  98.       VesaUnlockScreen      = (void *) dummy1;
  99.       VesaSetModified       = (void *) dummy1;
  100.       VesaSetPalette        = DosVesaSetPalette;
  101.       VesaGetPalette        = DosVesaGetPalette;
  102.       VesaGetCharacter      = DosVesaGetCharacter;
  103.       VesaKeyboardHit       = DosVesaKeyboardHit;
  104.       if (DosMouseOpen())
  105.         {
  106.           MouseOpen        = DosMouseOpen;
  107.           MouseClose       = DosMouseClose;
  108.           MouseShow        = DosMouseShow;
  109.           MouseHide        = DosMouseHide;
  110.           MouseSetPosition = DosMouseSetPosition;
  111.           MouseGetPosition = DosMouseGetPosition;
  112.           MouseGetEvent    = DosMouseGetEvent;
  113.         }
  114.       else
  115.         {
  116.           MouseOpen        = (void *) dummy2;
  117.           MouseClose       = (void *) dummy2;
  118.           MouseShow        = (void *) dummy2;
  119.           MouseHide        = (void *) dummy2;
  120.           MouseSetPosition = (void *) dummy2;
  121.           MouseGetPosition = (void *) dummy2;
  122.           MouseGetEvent    = (void *) dummy2;
  123.         }
  124.     }
  125.   return(TRUE);
  126. }
  127.  
  128. static VESABOOL _VesaGetInfo(PVESAINFO pVesaInfo)
  129. {
  130.   return(VesaInitialize() && VesaGetInfo(pVesaInfo));
  131. }
  132.  
  133. static VESABOOL _VesaGetModeInfo(VESAWORD Mode, PVESAMODEINFO pVesaModeInfo)
  134. {
  135.   return(VesaInitialize() && VesaGetModeInfo(Mode, pVesaModeInfo));
  136. }
  137.  
  138. static VESABOOL _VesaSetMode(VESAWORD Mode)
  139. {
  140.   return(VesaInitialize() && VesaSetMode(Mode));
  141. }
  142.  
  143. static VESABOOL _VesaGetMode(PVESAWORD Mode)
  144. {
  145.   return(VesaInitialize() && VesaGetMode(Mode));
  146. }
  147.  
  148. static VESABOOL _VesaSetWindow(VESACHAR Window, VESAWORD Address)
  149. {
  150.   return(VesaInitialize() && VesaSetWindow(Window, Address));
  151. }
  152.  
  153. static VESABOOL _VesaGetWindow(VESACHAR Window, PVESAWORD Address)
  154. {
  155.   return(VesaInitialize() && VesaGetWindow(Window, Address));
  156. }
  157.  
  158. static VESABOOL _VesaSetScanlineLength(VESAWORD NumberOfPixels)
  159. {
  160.   return(VesaInitialize() && VesaSetScanlineLength(NumberOfPixels));
  161. }
  162.  
  163. static VESABOOL _VesaGetScanlineLength(PVESAWORD BytesPerScanline,
  164.                                        PVESAWORD NumberOfPixels,
  165.                                        PVESAWORD NumberOfScanlines)
  166. {
  167.   return(VesaInitialize() && VesaGetScanlineLength(BytesPerScanline,
  168.                              NumberOfPixels, NumberOfScanlines));
  169. }
  170.  
  171. static VESABOOL _VesaSetSwitchFunc(VESASWITCH SwitchFunc)
  172. {
  173.   return(VesaInitialize() && VesaSetSwitchFunc(SwitchFunc));
  174. }
  175.  
  176. static VESABOOL _VesaLockScreen (VESACHAR wait)
  177. {
  178.   return(VesaInitialize() && VesaLockScreen(wait));
  179. }
  180.  
  181. static VESABOOL _VesaUnlockScreen (void)
  182. {
  183.   return(VesaInitialize() && VesaUnlockScreen());
  184. }
  185.  
  186. static VESABOOL _VesaSetModified (void)
  187. {
  188.   return(VesaInitialize() && VesaSetModified());
  189. }
  190.  
  191. static VESABOOL _VesaSetPalette(VESAWORD   StartIndex,
  192.                                 VESAWORD   NumberOfEntries,
  193.                                 PCVESACHAR Palette,
  194.                                 VESABOOL   Wait)
  195. {
  196.   return(VesaInitialize() && VesaSetPalette(StartIndex, NumberOfEntries,
  197.                                             Palette, Wait));
  198. }
  199.  
  200. static VESABOOL _VesaGetPalette(VESAWORD StartIndex,
  201.                                 VESAWORD NumberOfEntries,
  202.                                 PVESACHAR Palette)
  203. {
  204.   return(VesaInitialize() && VesaGetPalette(StartIndex, NumberOfEntries, Palette));
  205. }
  206.  
  207. static VESABOOL _VesaGetCharacter(PVESACHAR pchar)
  208. {
  209.   return(VesaInitialize() && VesaGetCharacter(pchar));
  210. }
  211.  
  212. static VESABOOL _VesaKeyboardHit(void)
  213. {
  214.   return(VesaInitialize() && VesaKeyboardHit());
  215. }
  216.  
  217. static VESABOOL _MouseOpen(void)
  218. {
  219.   return(VesaInitialize() && MouseOpen());
  220. }
  221.  
  222. static VESABOOL _MouseClose(void)
  223. {
  224.   return(VesaInitialize() && MouseClose());
  225. }
  226.  
  227. static VESABOOL _MouseShow(void)
  228. {
  229.   return(VesaInitialize() && MouseShow());
  230. }
  231.  
  232. static VESABOOL _MouseHide(void)
  233. {
  234.   return(VesaInitialize() && MouseHide());
  235. }
  236.  
  237. static VESABOOL _MouseSetPosition(VESAWORD x, VESAWORD y)
  238. {
  239.   return(VesaInitialize() && MouseSetPosition(x, y));
  240. }
  241.  
  242. static VESABOOL _MouseGetPosition(PVESAWORD x, PVESAWORD y)
  243. {
  244.   return(VesaInitialize() && MouseGetPosition(x, y));
  245. }
  246.  
  247. static VESABOOL _MouseGetEvent(PVESAWORD x, PVESAWORD y, PVESAWORD status, VESABOOL wait)
  248. {
  249.   return(VesaInitialize() && MouseGetEvent(x, y, status, wait));
  250. }
  251.  
  252. VESABOOL (*VesaGetInfo)(PVESAINFO pVesaInfo) = _VesaGetInfo;
  253. VESABOOL (*VesaGetModeInfo)(VESAWORD Mode, PVESAMODEINFO pVesaModeInfo) = _VesaGetModeInfo;
  254.  
  255. VESABOOL (*VesaSetMode)(VESAWORD Mode)  = _VesaSetMode;
  256. VESABOOL (*VesaGetMode)(PVESAWORD Mode) = _VesaGetMode;
  257.  
  258. VESABOOL (*VesaSetWindow)(VESACHAR Window, VESAWORD Address)  = _VesaSetWindow;
  259. VESABOOL (*VesaGetWindow)(VESACHAR Window, PVESAWORD Address) = _VesaGetWindow;
  260.  
  261. VESABOOL (*VesaSetScanlineLength)(VESAWORD NumberOfPixels)     = _VesaSetScanlineLength;
  262. VESABOOL (*VesaGetScanlineLength)(PVESAWORD BytesPerScanline,
  263.                                   PVESAWORD NumberOfPixels,
  264.                                   PVESAWORD NumberOfScanlines) = _VesaGetScanlineLength;
  265.  
  266. VESABOOL (*VesaSetSwitchFunc)(VESASWITCH SwitchFunc) = _VesaSetSwitchFunc;
  267. VESABOOL (*VesaLockScreen)(VESACHAR wait)            = _VesaLockScreen;
  268. VESABOOL (*VesaUnlockScreen)(void)                   = _VesaUnlockScreen;
  269. VESABOOL (*VesaSetModified)(void)                    = _VesaSetModified;
  270.  
  271. VESABOOL (*VesaSetPalette)(VESAWORD   StartIndex,
  272.                            VESAWORD   NumberOfEntries,
  273.                            PCVESACHAR Palette,
  274.                            VESABOOL   Wait)          = _VesaSetPalette;
  275. VESABOOL (*VesaGetPalette)(VESAWORD StartIndex,
  276.                            VESAWORD NumberOfEntries,
  277.                            PVESACHAR Palette)        = _VesaGetPalette;
  278.  
  279. VESABOOL (*VesaGetCharacter)(PVESACHAR pchar)        = _VesaGetCharacter;
  280. VESABOOL (*VesaKeyboardHit)(void)                    = _VesaKeyboardHit;
  281.  
  282. VESABOOL (*MouseOpen)(void)                          = _MouseOpen;
  283. VESABOOL (*MouseClose)(void)                         = _MouseClose;
  284. VESABOOL (*MouseShow)(void)                          = _MouseShow;
  285. VESABOOL (*MouseHide)(void)                          = _MouseHide;
  286. VESABOOL (*MouseSetPosition)(VESAWORD x, VESAWORD y) = _MouseSetPosition;
  287. VESABOOL (*MouseGetPosition)(PVESAWORD x,
  288.                              PVESAWORD y)            = _MouseGetPosition;
  289. VESABOOL (*MouseGetEvent)(PVESAWORD x, PVESAWORD y,
  290.                           PVESAWORD status,
  291.                           VESABOOL wait)             = _MouseGetEvent;
  292.